home *** CD-ROM | disk | FTP | other *** search
- Path: pegasus.montclair.edu!harmon
- From: harmon@pegasus.montclair.edu (Derek Harmon)
- Newsgroups: comp.lang.c
- Subject: Re: Limit on #bytes inside of struct?
- Date: 12 Feb 1996 15:31:18 -0500
- Organization: Montclair State University
- Message-ID: <harmon.824157042@pegasus.montclair.edu>
- References: <4feg1d$d4g@cville-srv.wam.umd.edu> <4ffg6b$ivd@sparcserver.lrz-muenchen.de> <4ffohq$1gb@mordred.gatech.edu> <4ffun7$1l4l@cymbal.aix.calpoly.edu> <311F15D8.78D1@zess.uni-siegen.de>
- NNTP-Posting-Host: pegasus.montclair.edu
- X-Newsreader: NN version 6.5.0 #68 (NOV)
-
- ** Quoting a message by <becker@zess.uni-siegen.de> dated <12-Feb-1996>:
- > No it isn't, see below.
-
- Yes it is, see below below. :)
-
- > > typedef struct {
- > > int the_array[50000];
- > > } struct_type;
- >
- > This way, you don't put the 50K numbers in the struct, but only
- > a pointer to them. Should be at most 4 bytes.
-
- First of all, we should agree that there are 50,000 continiguous integers
- *SOMEPLACE*. We can rule out having malloc'd them, so they aren't sitting
- on the heap, as they haven't been dynamically allocated. In fact, this is
- a static allocation of an array with a fixed number of elements, determined
- at compile-time.
-
- I believe you've confused the degeneration of an array name, when used
- without square brackets, into a pointer during execution; and the declaration
- of arrays and pointers.
-
- int *p; /* This is a pointer to an integer, a pointer's declaration will
- * always feature a asterisk (*). */
-
- int n[10]; /* This is an array declaration, it will always feature square
- * brackets ([]). */
- int main(void)
- {
- ...
- p++; /* This is a POINTER, whose address is incremented by sizeof(int) */
- n[1] = *p + 2; /* This is the VALUE at p being added to 2 and placed
- * into the second spot of array n. */
- n[1] = n[0] + 2; /* This is the VALUE of n's first spot, plus 2, and
- * placed into the second spot of array n. */
- p = n; /* This sets p, a POINTER, to n, here having degenerated from an
- * ARRAY into a POINTER. */
- ...
- }
-
- So some observations become clear. In your data declarations, pointers
- always have *'s, arrays always have []'s. In your program, pointers that
- are being "dereferenced," or producing a value to which they point, will
- always have *'s, and arrays producing a value of which they hold, will
- always have []'s. Only within your function declarations when an array
- name is w/o []'s and a pointer is w/o *'s are they rougly equivalent (and
- then, they have nothing to do with ints, chars, or other single variables
- which NEVER have *'s or []'s associated with them).
-
- > > int the_array[50000];
- ^ ^
- ! !
- Therefore, these square brackets betray this as an Array Declaration,
- not a Pointer Declaration, which would have looked like this,
-
- : int *the_array;
- ^
- !
- (This shouts POINTER!)
-
- -- Stone
- --
- # Derek Harmon (aka Stonelight) harmon@pegasus.montclair.edu
- # - Computer Science Undergrad, Montclair State University, NJ
- # - My views are my own, nobody else is this creative. 3;)>
- ... Santa's elves are just a bunch of subordinate Clauses.
-
-